#!/bin/bash
#项目名
CI_PROJECT_NAME=$1
#分支名
CI_BUILD_REF_NAME=$2
#用户名
USER=$3
#最新commit值
CI_COMMIT_SHA=$4
#打包路径
PACK_PATH=$5
#部署路径
DEPLOY_PATH=$6

echo "-----------BEGIN 代码部署 BEGIN-----------"
echo "发布包 $PACK_PATH/${CI_COMMIT_SHA:0:8}.${USER}.tar.gz"
if [ ! -d  ${DEPLOY_PATH} ]
then
  echo "发布目录不存在，待创建"
  mkdir -p ${DEPLOY_PATH}
  echo "发布目录创建完毕"
fi
cp $PACK_PATH/${CI_COMMIT_SHA:0:8}.${USER}.tar.gz ${DEPLOY_PATH}
cd ${DEPLOY_PATH}

rm -rf output/
tar -zxf ${CI_COMMIT_SHA:0:8}.${USER}.tar.gz
echo "进入output"
cd output

###### fangjian
res_dir="/data/nuxt/resource/ssjj2res/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}"
[ -d $res_dir ] && rm -rf $res_dir  || echo "pass"
[ ! -d $res_dir ] && mkdir -p $res_dir || echo "mkdir"
cp -r dist $res_dir

rm -rf ${CI_COMMIT_SHA:0:8}.${USER}.tar.gz
echo "-----------END 代码部署完毕 END-----------"
